<?php


namespace m;


use think\Model;

class BasicM extends Model
{
    //计算分页
    public function pageCount($count,$limit = 10)
    {
        $count = is_int($count) ? $count : current($count);
        if(is_array($count)) $count = current($count);
        return ceil( $count / $limit);
    }

    /**
     * demo =>[
     *      ['id','=',1],
     *      ['status','>',-1]
     * ]
     * auth WQl
     * 2021/6/16 16:56
     * @param $where
     * @return string
     */
    public function encodeWhere($where): string
    {
        $str = "";
        $first = true;
        foreach ($where as $v){
            $str .= $first ?  "`{$v[0]}` {$v[1]} '{$v[2]}'" : "AND `{$v[0]}` {$v[1]} '{$v[2]}'";
            $first = false;
        }
        return $str;
    }
}